GdkGLContext: Track shared context
authorAlexander Larsson <alexl@redhat.com>
Thu, 30 Oct 2014 11:04:23 +0000 (12:04 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 30 Oct 2014 11:43:03 +0000 (12:43 +0100)
This allows us to read it back, but primarily it ensures
the shared context wrapper stays alive as long as the context.

gdk/gdkglcontext.c
gdk/wayland/gdkglcontext-wayland.c
gdk/x11/gdkglcontext-x11.c

index 748d9322dd2249cb78a623b278b0a5dfc3cd8985..b15b76eaddccba5c977a509788882f63080a85dd 100644 (file)
@@ -82,6 +82,7 @@
 typedef struct {
   GdkWindow *window;
   GdkVisual *visual;
+  GdkGLContext *shared_context;
 
   guint realized : 1;
   guint use_texture_rectangle : 1;
@@ -93,6 +94,7 @@ enum {
 
   PROP_WINDOW,
   PROP_VISUAL,
+  PROP_SHARED_CONTEXT,
 
   LAST_PROP
 };
@@ -118,6 +120,7 @@ gdk_gl_context_dispose (GObject *gobject)
 
   g_clear_object (&priv->window);
   g_clear_object (&priv->visual);
+  g_clear_object (&priv->shared_context);
 
   G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject);
 }
@@ -155,6 +158,15 @@ gdk_gl_context_set_property (GObject      *gobject,
       }
       break;
 
+    case PROP_SHARED_CONTEXT:
+      {
+        GdkGLContext *context = g_value_get_object (value);
+
+        if (context != NULL)
+          priv->shared_context = g_object_ref (context);
+      }
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
     }
@@ -178,6 +190,10 @@ gdk_gl_context_get_property (GObject    *gobject,
       g_value_set_object (value, priv->visual);
       break;
 
+    case PROP_SHARED_CONTEXT:
+      g_value_set_object (value, priv->shared_context);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
     }
@@ -220,6 +236,22 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
                          G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GdkGLContext:shared-context:
+   *
+   * The #GdkGLContext that this context is sharing data with, or #NULL
+   *
+   * Since: 3.16
+   */
+  obj_pspecs[PROP_SHARED_CONTEXT] =
+    g_param_spec_object ("shared-context",
+                         P_("Shared context"),
+                         P_("The GL context this context share data with"),
+                         GDK_TYPE_GL_CONTEXT,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS);
+
   gobject_class->set_property = gdk_gl_context_set_property;
   gobject_class->get_property = gdk_gl_context_get_property;
   gobject_class->dispose = gdk_gl_context_dispose;
@@ -351,6 +383,26 @@ gdk_gl_context_get_window (GdkGLContext *context)
   return priv->window;
 }
 
+/**
+ * gdk_gl_context_get_shared_context:
+ * @context: a #GdkGLContext
+ *
+ * Retrieves the #GdkGLContext that this @context share data with.
+ *
+ * Returns: (transfer none): a #GdkGLContext or %NULL
+ *
+ * Since: 3.16
+ */
+GdkGLContext *
+gdk_gl_context_get_shared_context (GdkGLContext *context)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
+
+  return priv->shared_context;
+}
+
 /**
  * gdk_gl_context_clear_current:
  *
index 5a75c547481ad6f61f2642d077acbe55ea5322ec..ee8782d3ea27750bd6c6f7781f1cbe000cc85782 100644 (file)
@@ -364,6 +364,7 @@ gdk_wayland_window_create_gl_context (GdkWindow     *window,
   context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
                           "window", window,
                           "visual", gdk_window_get_visual (window),
+                          "shared-context", share,
                           NULL);
 
   context->egl_config = config;
index b7a90eb1774ffaec49812977a434b5a2adf82770..071f8a1319a1a776a28a7769945d8a029551b357 100644 (file)
@@ -1124,6 +1124,7 @@ gdk_x11_window_create_gl_context (GdkWindow    *window,
   context = g_object_new (GDK_TYPE_X11_GL_CONTEXT,
                           "window", window,
                           "visual", gdk_visual,
+                          "shared-context", share,
                           NULL);
 
   context->profile = profile;